package com.tc.activiti.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zengqingfa
 * @date 2019/10/21 14:44
 * @description
 * @email zengqingfa_java@163.com
 */
@Component
public class IframeFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        //必须
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        //实际设置
        response.setHeader("x-frame-options", "SAMEORIGIN");
        //调用下一个过滤器（这是过滤器工作原理，不用动）
        chain.doFilter(request, response);
    }

    public void destroy() {
    }

}
